@extends('layouts.base')
@section('title', '产品分类管理')
@section('admin-style')
    <link rel="stylesheet" href="{{ asset('/assets/plugins/dropify/dist/css/dropify.min.css') }}">
@stop
@section('content')
    <div class="container-fluid">
        <!-- ============================================================== -->
        <!-- Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <div class="row page-titles">
            <div class="col-md-5 align-self-center">
                <h3 class="text-themecolor">产品分类管理-添加</h3>
            </div>
            <div class="col-md-7 align-self-center">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="javascript:void(0)">首页</a></li>
                    <li class="breadcrumb-item">产品分类管理</li>
                    <li class="breadcrumb-item active">产品分类修改</li>
                </ol>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header bg-success">
                        <h4 class="m-b-0 text-white">修改</h4>
                    </div>
                    <div class="card-body"></div>
                    <div class="card-body">
                        <form role="form">
                            @csrf
                            <div class="form-body">
                                <div class="form-group row">
                                    <label class="control-label text-right col-md-2" for="">分类名称：</label>
                                    <div class="col-md-7">
                                        <input class="form-control form-white category-name" placeholder="输入分类名称" value="@if(!empty($result)){{$result->goods_name}}@endif" type="text" name="category-name">
                                        <span class="category_title" style="color:red;display:none;">输入分类名称</span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-8">
                                        <div class="row">
                                            <div class="offset-sm-3 col-md-9">
                                                <button type="button" class="btn btn-success waves-effect waves-light save-category" data-dismiss="modal">保存</button>
                                                <a href="{{ route('admin.goodstype.index') }}"><button type="button" class="btn btn-danger"><i class=" fas fa-times"></i> 取消</button></a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="{{asset('assets/js/jquery.min.js')}}"></script>
    <script>
         $(".category_name").focus(function(){
            $(this).css('border-color','#ced4da');
            $(".category_title").css('display','none');
        });
        $(".save-category").click(function () {
            var category_name = $(".category-name").val();
            var id = '{{$result->id}}'

            if(!category_name){
                $('.category_name').css('border-color','red')
                $('.category_title').css('display','block');
                return;
            }
            var formData = new FormData();
            formData.append('id', id)
            formData.append('goodsName', category_name)
            $.ajax({
                type: 'post',
                url: '/admin/goodsType/update',
                data: formData,
                dataType: 'json',
                cache: false,
                processData: false,
                contentType: false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(data) {
                    if (!data.flag) {
                        window.close(data.msg);
                        return;
                    }
                    window.close(data.msg);
                    window.location.href='/admin/goodsType';
                },
            })
        })
    </script>
@stop


